//
//  NSObjectCategory.m
//  ubixar-utils
//
//  Created by Demis Bellot on 17/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "NSObjectCategory.h"

@implementation NSObject (NSObjectCategory)

- (void)performSelector:(SEL)aSelector withEachObjectFrom:(id)collection
{
    NSEnumerator *objectEnumerator = [collection objectEnumerator];
    id object;
	
    while(object = [objectEnumerator nextObject])
    {
		[self performSelector:aSelector withObject:object];
    }
}

- (NSArray *)resultsOfPerformingSelector:(SEL)aSelector withEachObjectFrom:(id)collection
{
    NSEnumerator *objectEnumerator = [collection objectEnumerator];
    NSMutableArray *results = [NSMutableArray array];
    id object, result;
	
    while(object = [objectEnumerator nextObject])
    {
        result = [self performSelector:aSelector withObject:object];
        if (result == nil)
            result = [NSNull null];
        [results addObject:result];
    }
    return results;
}

- (void)log
{
    NSLog(@"%@",self);
}

- (id)arrayByAddingObject:(id)anObject
{
    return [NSArray arrayWithObjects:self, anObject, nil]; // NSArray will still behave normally, too
}
@end